//
// Abandoned Mine adventure object handling
//
// L. Dean Gibson II 3/8/01
//

#ifndef ABANDONED_MINE_H_INCLUDED
#define ABANDONED_MINE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "bool_array.h"
#include "creature_array.h"
#include "materials.h"
#include "ownable_event_list.h"
#include "scriptable_event.h"
#include "sized_int_types.h"
#include "stationary_adventure_object.h"


// ------------------------------------------------------------------------
// fight creatures to get a mine
// ------------------------------------------------------------------------
class t_adv_abandoned_mine : public t_stationary_adventure_object, public t_creature_array
{
public:
	t_adv_abandoned_mine(  std::string const& source );

	virtual float	 		ai_value( t_adventure_ai const& ai, t_creature_array const& army, int move_cost ) const;	
	virtual float			ai_activation_value_drop( t_creature_array const& army ) const;
	virtual void			activate_trigger( t_army* army, t_adv_map_point const& point, 
							                  t_direction direction, t_adventure_frame* frame );
	t_material				get_material() const;
	virtual t_skill_mastery	get_anti_stealth_level() const;
	virtual int				get_version() const;
	virtual void	 		initialize( t_adventure_map& map );
	virtual void			on_begin_turn();
	virtual void			on_combat_end( t_army* army, t_combat_result result,
									   t_creature_array* losses, t_adventure_frame* frame );		
	virtual void			on_end_turn();
    virtual void			place( t_adventure_map& map, t_adv_map_point const& point );
	virtual bool			preplacement( t_adventure_map& map, int pass );
	virtual bool			process_continuous_events( t_adventure_map& map );
	virtual void			process_new_day();
	virtual bool			process_triggerable_events( t_adventure_map& map, std::string const& name );
	virtual bool			process_timed_events( t_adventure_map& map, bool start_of_day = true );
	virtual void			right_click( t_mouse_event const& event,
									      t_adventure_frame* adventure_frame );
	virtual bool			read( std::streambuf&					 stream, 
								  t_qualified_adv_object_type const& type,
								  int								 version );
	virtual bool			read_from_map( std::streambuf& buffer, t_progress_handler* handler );
	virtual void			read_postplacement( t_adventure_map& map );
	virtual bool			write( std::streambuf& stream ) const;

protected:

	void	default_garrison();
	void	execute_script(t_garrison_scriptable_event event_id, t_army* army);
	bool	read_built_in_events_from_map( std::streambuf& stream, t_uint16 format_version );
	bool	read_continuous_events_from_map( std::streambuf& stream, t_uint16 format_version );
	bool	read_events( std::streambuf& stream, int version );
	bool	read_garrison_from_map( std::streambuf& stream, t_uint16 format_version );
	bool	read_timed_events_from_map( std::streambuf& stream, t_uint16 format_version );
	bool	read_triggerable_events_from_map( std::streambuf& stream, t_uint16 format_version );
	bool	write_events( std::streambuf& stream ) const;
	void	visit( t_army* army, t_adventure_frame* frame, t_creature_array& losses );

	t_ownable_built_in_event_ptr		m_built_in_events[ k_garrison_scriptable_event_count ];
	t_ownable_continuous_event_list		m_continuous_events;
	t_ownable_timed_event_list			m_timed_events;
	t_ownable_triggerable_event_list	m_triggerable_events;
	t_bool_array						m_visited;
};

// ------------------------------------------------------------------------
// The type of materials in this mine
// ------------------------------------------------------------------------
inline t_material t_adv_abandoned_mine::get_material() const
{
	return t_material( get_type().major_subtype() );
}


#endif // ABANDONED_MINE_H_INCLUDED
